//
//  StuRefuseVC.m
//  test
//
//  Created by 朱圳 on 2018/3/16.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "StuRefuseVC.h"
#import "HisOrderHead.h"
#import "HisOrderCell.h"
#import "OrderModel.h"
#import "StudyContent.h"
@interface StuRefuseVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray <OrderModel*>*stuArray;
@property(nonatomic,strong)UITableView *tableView;

@end

@implementation StuRefuseVC

- (void)viewDidLoad {
    [super viewDidLoad];
     [self.view addSubview:self.tableView];
    self.view.backgroundColor = [UIColor whiteColor];
}

-(void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
    [self requestData];
}

-(void)requestData{
        [EasyShowLodingView showLodingText:@""];
    __weak typeof(self) weakSelf = self;
    NSDictionary *dict = @{
                           @"gid" : Gid,
                           @"gpass" : Gpassword,
                           };
    [[AFNetworkTool shareManager]postJSONWithUrl:GR_Readylist parmas:dict successData:^(id json) {
            [self.stuArray removeAllObjects];
        NSArray *arr = json[@"data"];
        for (int i = 0; i<arr.count; i++) {
            OrderModel *model = [OrderModel yy_modelWithJSON:arr[i]];
            
            if ([model.isornot isEqualToString:@"1"] && [model.sdisnot isEqualToString:@"2"]) {
                
                [weakSelf.stuArray addObject:model];
            }
            
        }
        self.stuArray = (NSMutableArray *)[[self.stuArray reverseObjectEnumerator] allObjects];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [EasyShowLodingView hidenLoding];
            if (self.stuArray.count==0) {
                [self.tableView removeFromSuperview];
                KongDataView *konview=[KongDataView NilDataview];
                konview.frame=self.view.frame;
                [self.view addSubview:konview];
            }
        });
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
        });
    } failure:^(NSError *error) {
                [EasyShowLodingView hidenLoding];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.stuArray.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HisOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hisOrderCell"];
    if (!cell) {
        cell = [[HisOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"hisOrderCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.gmol = self.stuArray[indexPath.row];
    return cell;
    
}
/** 区头视图 */
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (self.stuArray.count>0) {
        HisOrderHead *header = [[HisOrderHead alloc] initWithReuseIdentifier:@"header"];
        return header;
    }else{
        return nil;
    }
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    StudyContent *vc = [[StudyContent alloc]init];
    vc.model = self.stuArray[indexPath.row];
     vc.type = @"3";
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 懒加载
-(NSMutableArray *)stuArray{
    if (!_stuArray) {
        _stuArray = [[NSMutableArray alloc]init];
    }
    return _stuArray;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)style:UITableViewStyleGrouped];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[HisOrderCell class] forCellReuseIdentifier:@"hisOrderCell"];
    }
    return _tableView;
}
@end


